package com.dx.hotel;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.lang3.StringUtils;

import com.dx.common.base.util.CommonConstants;
import com.dx.common.base.util.DateUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.mchange.v1.util.ArrayUtils;
import com.travelsky.hotelbesdk.cache.api.DefaultMultiHotelCacheAPI;
import com.travelsky.hotelbesdk.cache.api.DefaultSingleHotelCacheAPI;
import com.travelsky.hotelbesdk.cache.api.MultiHotelCacheAPI;
import com.travelsky.hotelbesdk.cache.api.SingleHotelCacheAPI;
import com.travelsky.hotelbesdk.cache.models.condition.DefaultMultiHotelCacheReqCondition;
import com.travelsky.hotelbesdk.cache.models.condition.DefaultSingleHotelCacheReqCondition;
import com.travelsky.hotelbesdk.models.easyhotel.multi.HotelRatePlan;
import com.travelsky.hotelbesdk.models.easyhotel.multi.HotelRoomRate;
import com.travelsky.hotelbesdk.models.easyhotel.multi.SingleHotel;
import com.travelsky.hotelbesdk.models.response.EasyMultiHotelResponse;
import com.travelsky.hotelbesdk.models.response.EasySingleHotelResponse;
import com.travelsky.hotelbesdk.utils.Hotelbe_Biz_Exception;

public class HotelController  extends Controller{
	public void index() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {	
		//已登录则跳转到登陆成功页面
		if(this.getSession().getAttribute("user")!=null)
			redirect("/");
		else {
			SingleHotelCacheAPI singleCache=new DefaultSingleHotelCacheAPI();
			DefaultSingleHotelCacheReqCondition condition=new DefaultSingleHotelCacheReqCondition();
			condition.setCheckInDate(DateUtil.getDateStr()); 
			condition.setCheckOutDate(DateUtil.getDateStrByAdd(CommonConstants.DATE_ADD_TYPE_DAY, 3)); 
			
			condition.setHotelCode(this.getPara("hotelcode"));			
			
			try {
				long i=System.currentTimeMillis();
				EasySingleHotelResponse respone=singleCache.getSingleHotel(condition);
				System.out.println(System.currentTimeMillis()-i+" ms");		
				respone.getSinglehotel().getBasichotelinfo().getHotelAmenities();
				 System.out.println("getBasichotelinfo:"+BeanUtils.describe(respone.getSinglehotel().getBasichotelinfo()));
				 System.out.println(respone.getSinglehotel().getRoomtypeinfo().get(0).getVendorList().size());
				 System.out.println("getVendorList:"+BeanUtils.describe(respone.getSinglehotel().getRoomtypeinfo().get(0).getVendorList().get(0)));;
				//respone.getSinglehotel().getBasichotelinfo().GETM;
				this.setAttr("hotelList", respone.getSinglehotel());
			} catch (Hotelbe_Biz_Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
			render("/WEB-INF/jsp/hotel/hotel.jsp");
		}
	}
	
	public void test(){
		render("/WEB-INF/jsp/test/auto.jsp");
	}
}
